<?php
class item {
	private $_articletable = 'qcms_item';
	
	public function add($data) {
		if(empty($data['title']) || empty($data['categoryid']) || empty($data['content'])) {
			return 0;
		}
		
		$data['title'] = trim($data['title']);
		$data['categoryid'] = intval($data['categoryid']);
		$data['content'] = trim($data['content']);
		$data['status'] = isset($data['status']) ? $data['status'] : 0;
		$data['createtime'] = time();
		
		$conn = mysql_connect('localhost', 'root', 'quanhz');
		mysql_select_db('qcms');
		mysql_query('SET NAMES UTF8');
		
		$sql = "INSERT INTO `{$this->_articletable}` (`title`, `categoryid`, `status`, `createtime`) VALUES ('{$data['title']}', '{$data['categoryid']}', '{$data['status']}', '{$data['createtime']}')";
		if(mysql_query($sql)) {
			$itemid = mysql_insert_id();
			return mysql_query("INSERT INTO `{$this->_articletable}content` (`itemid`, `content`) VALUES ('$itemid', '{$data['content']}')");			
		} else {
			return 0;
		}
	}
	
	public function delete($itemid) {
		
	}
	
	public function get($itemid) {
		
	}
}